home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
asmutil
/
asm_n_z.zip
/
WT.ASM
< prev
next >
Wrap
Assembly Source File
|
1987-03-12
|
23KB
|
471 lines
TITLE WalkTree - Execute Program at Every Level of Tree
; Copyright Notice:
;
; The program WalkTree, both in binary executable and source forms, is
; in the public domain. No warranty is given or implied, and no
; liability will be assumed by the author.
;
; Everyone on earth is hereby given permission to use, copy, distribute,
; change, mangle, destroy or otherwise employ these programs, in whole
; or in part, in any fashion they so desire, provided they hurt no one
; but themselves in the process.
;
; If anyone has any questions about this or any other program that I
; have authored, I can be reached by messages on any of the following
; systems:
;
; Bob's Answering Machine (602) 242-3158 300/1200 bps
; FIDO 114/1 Phoenix Node (602) 242-5230 300/1200/2400 bps
; FIDO 114/446 XTRA #1 (602) 979-6352 300/1200/2400 bps
; Technoids Anonymous (602) 899-4876 300/1200/2400 bps
;
; All excellent 24 hour systems.
;
; Don A. Williams
; 3913 W. Solano Dr. N.
; Phoenix, AZ 85019
; This version of the source for WalkTree has been set up for assembly by
; SpeedWare's very good TurboEditAsm. To convert it for assembly by
; Microsoft's MASM will require the addition of Segment and Assume
; statements, at least.
;
;
; version history
; modified by John Covici
; 3 Wirt Street NW
; Leesburg, VA 22075
; March 12, 1987 fixed the following bugs:
; (1) append cr to generated command line (if not dos goes out to lunch)
; (2) now assembles with masm
; (3) to get environment segment had to say [ds:2ch] instead of [2ch]
; otherwise assembler ignored brackets without error
LF EQU 0AH ; ASCII Line Feed
CR EQU 0DH ; ASCII Carriage Return
cseg segment para public 'code'
ORG 0100H
assume cs:cseg,ds:cseg,ss:cseg
Start: jmp Begin ; Jump over data area
;------ Messages
LogOn db 'WalkTree: Version 1.01 - March 12, 1987',CR,LF,LF,'$'
BadVer db 'WalkTree requires Dos 2.0 or greater',CR,LF,'$'
UseMsg db 'USAGE: WalkTree <any dos command>',CR,LF,'$'
EndMs1 db CR,LF,'Number of directories= $'
EndMs2 db ': Maximum depth= $'
EndMsg db '$'
AbtMsg db 'Program terminated by operator.',CR,LF,'$'
;------ Constants and Other Data Storage
Path db 0,':\',65 DUP(0)
PatMsg db CR,LF,LF,'---'
CurPat db 0,':\',65 DUP(0)
PatTer db '---',CR,LF,0
MatAll db '*.*',0
Parent db '..',0
CmdTail db 0,'/c '
CmdLin db 128 DUP(0)
ComSpc db 'COMSPEC',0
ComCom db '\COMMAND.COM',0
DTAOfs dw 0 ; Save space for DTA: Offset and
DTASeg dw 0 ; ... Segment
SaveSS dw 0 ; Save space for Stack; Segment and
SaveSP dw 0 ; ... Pointer
Level dw 0 ; Current depth in hierarchy
MaxLev dw 0 ; Maximum depth in hierarchy
DirCnt dw 0 ; Count of directories processed
comand db 65 dup(0) ;space for command.com from env or default
;------ Parameter Block for DOS function 4B, Exec
ParBlk dw 0 ; Seg of environment string
dw 0 ; Ofs of Command Tail string
dw 0 ; Seg " " " "
dw 0 ; Ofs of Default FCB 1
dw 0 ; Seg " " " "
dw 0 ; Ofs of Default FCB 2
dw 0 ; Seg " " " "
;=========================================================================
; Beginning of Program Code
Begin: mov SP,offset STACK ; Set local stack
cld ; Clear Direction Flag [forward]
mov DX,offset LogOn ; Dsiplay logon message
mov AH,9 ; ... MS-DOS 'Print String'
int 21H ; ... DOS Entry Interrupt
mov AH,30H ; MS-DOS 'Get Version'
int 21H ; ... DOS Entry Interrupt
cmp AL,2 ; Check for 2.x or greater
jnb VerOk ; ... Xfr- 2.x or greater
mov DX,offset BadVer ; Get ptr to 'bad version' msg
ErrorExit:
mov AH,9 ; MS-DOS 'Print String'
int 21H ; ... DOS Entry Interrupt
int 20H ; DOS Terminate Program Interrupt
VerOk: mov AH,19H ; MS-DOS 'Get Current Disk'
int 21H ; ... DOS Entry Interrupt
add AL,'A' ; Convert disk code to alpha disk
mov Path,AL ; ... and save in Path
mov CurPat,AL ; ... and in Current Path
mov SI,offset Path+3 ; Get Current Dir as starting path
mov DL,0 ; ... current disk
mov AH,47H ; ... MS-DOS 'Get Current Directory'
int 21H ; ... DOS Entry Interrupt
mov SI,80H ; Get ptr to Command Line buffer
lodsb ; ... and get length
or AL,AL ; Check for length zero - no tail
jnz HaveTail ; ... Xfr - length not zero
Usage:
mov DX,offset UseMsg ; Display 'Usage' message and
jmp short ErrorExit ; ... terminate
HaveTail:
cbw ; Make length 16 bits
mov CX,AX ; ... and move to CX for move
add AL,3 ; Adjust length for '/c '
mov CmdTail,AL ; ... and store for DOS 4BH
mov DI,offset CmdLin ; Get ptr to internal Cmnd Line
repz movsb ; Move command line to internal store
mov byte ptr[di],0dh ;append carriage return
mov BX,1000H ; Release all but 1000H paragraphs
mov AH,4AH ; ... MS-DOS 'Modify Allocated Memory'
int 21H ; ... DOS Entry Interrupt
call WalkTree ; Walk the tree recursively
mov DX,offset EndMs1 ; Print out run statistics
mov AH,9 ; ... MS-DOS 'Print String'
int 21H ; ... DOS Entry Interrupt
mov BX,DirCnt ; Display directory count in
call PrintDecimal ; ... decimal
mov DX,offset EndMs2 ; Display 2nd part of message
mov AH,9 ; ... MS-DOS 'Print String'
int 21H ; ... DOS Entry Interrupt
mov BX,MaxLev ; Display maximum level in
call PrintDecimal ; ... decimal
mov DX,offset EndMsg ; Get ptr final part of message
Terminate:
mov AH,9 ; MS-DOS 'Print String'
int 21H ; ... DOS Entry Interrupt
mov DX,offset Path ; Restore directory to starting
mov AH,3BH ; ... MS-DOS 'Change Subdirectory'
int 21H ; ... DOS Entry Interrupt
int 20H ; DOS Terminate Program
;=========================================================================
; WalkTree is a recursive subroutine that processes each level of the
; directory hierarchy. Each invocation of Walktree creates and uses a
; 50 byte stack frame containing the Segment and Offset of the prior
; level's DTA, the name of the current subdirectory, and a pointer to